home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 7
/
FM Towns Free Software Collection 7.iso
/
taropyon
/
znsplay
/
src
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-30
|
10KB
|
421 lines
/*************************************************************************
* "ZNSPLAY"
*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#ifdef __HIGHC__
# include <heap.cf>
#endif
#include <egb.h>
#include <mos.h>
#include <snd.h>
#include <xld.h>
#include <sidework.h>
#include <loader.h>
#include "znsplay.h"
#include "../dll/bgm/midi.h"
#include <setint.h>
#include <doscons.h>
#include <spgetopt.h>
#include <fdl.h>
#include <fdl/fdlcol.h>
#include <dta.h>
#include <dtaname.h>
extern int SideWorkMenu(void);
static CONST char RECODENAME_MAINARG[] = DTA_RECODENAME_MAINARG;
DTACTRL_T *DtaCtrl = NULL;
static PLT_RGB PltDat[16] =
{
/* G R B */
{ 0, 0, 0}, /* C_BALCK */
{ 0, 0, 0}, /* C_BLUE or C_THROUGH */
{ 7, 7, 8}, /* C_RED */
{12,12,13}, /* C_MAGENTA */
{ 6, 5, 7}, /* C_GREEN */
{ 8, 7, 9}, /* C_CYAN */
{10, 9,11}, /* C_YELLOW */
{11,11,12}, /* C_WHITE */
{ 5, 5, 6}, /* C_HBALCK */
{ 0, 0,11}, /* C_HBLUE */
{ 0,11, 0}, /* C_HRED */
{ 0,11,11}, /* C_HMAGENTA */
{11, 0, 0}, /* C_HGEEN */
{11, 0,11}, /* C_HCYAN */
{11,11, 0}, /* C_HYELLOW */
{14,14,15} /* C_HWHITE */
};
POINT DisplayStartPara[4] =
{
{0,0}, /* 画面の表示開始一の設定 */
{0,0}, /* 仮想画面中の移動 */
{2,2}, /* 画面の拡大 */
{320,240}, /* 表示画面の大きさ */
};
void page1_palette(void)
{
DSP_writePage(1);
DSP_setPlt(PltDat);
}
void ZNS_displayStart( int mode, int x, int y )
{
DisplayStartPara[mode].x = x;
DisplayStartPara[mode].y = y;
EGB_displayStart(EgbPtr, mode, DisplayStartPara[mode].x,
DisplayStartPara[mode].y );
}
#if 0
void reinit(void)
{
int page;
{
int i;
page = 0;
for ( i = 0; i < 4; ++i )
{
EGB_displayStart(EgbPtr, i, DisplayStartPara[i].x,
DisplayStartPara[i].y );
}
}
{
page = 1;
EGB_writePage(EgbPtr, page );
EGB_displayStart(EgbPtr, 1, DspCtrl.scinf[page].dspstart.x,
DspCtrl.scinf[page].dspstart.y );
EGB_displayStart(EgbPtr, 3, DspCtrl.scinf[page].sc.x2+1,
DspCtrl.scinf[page].sc.y2+1 );
}
MOS_setControl(0x7F);
MOS_resolution(0,DspCtrl.page0);
MOS_resolution(1,DspCtrl.page1);
MOS_writePage(MosInf.page);
MOS_curType( 81 );
MosInf.move = DspCtrl.scinf[MosInf.page].sc;
MOS_moveArea( MosInf.move.x1, MosInf.move.y1,
MosInf.move.x2, MosInf.move.y2 );
page1_palette();
}
#endif
/*************************************************************************
* システム初期化
*************************************************************************/
static int init( int *argc, char **argv[], int _argc, char **_argv )
{
DTARECODE_T *arg_recode = NULL;
#ifdef __HIGHC__
/* メモリ取得用設定 */
Init_allocated_storage = 0;
#endif
*argc = _argc;
*argv = _argv;
if ( DTA_isAtPcl() )
{
/* 子プロセス起動 */
char *args = "ZNSPLAY";
if ( (DtaCtrl = DTA_openCheck()) != NULL )
{
if ( (arg_recode = DTA_openRecode( DtaCtrl, RECODENAME_MAINARG)) != NULL )
{ /* パラメータの指定あり */
args = arg_recode->ptr;
}
}
if ( (*argc = FS_argSet( args, argv )) < 1 )
return (ERR);
}
set_ctrl_c();
set24h();
if ( SndPtr == NULL )
{
if ( (SndPtr = calloc(16384,1)) == NULL )
{
reset24h();
return (ERR);
}
SND_init( SndPtr );
}
DSPCTRL dsp;
dsp = DspCtrl;
dsp.page0 = ZNS_RESOLUSION;
dsp.scinf[0].md = ZNS_RESOLUSION;
dsp.scinf[0].fr.x1 = 0;
dsp.scinf[0].fr.y1 = 0;
dsp.scinf[0].fr.x2 = 511;
dsp.scinf[0].fr.y2 = 255;
dsp.scinf[0].sc.x1 = 0;
dsp.scinf[0].sc.y1 = 0;
dsp.scinf[0].sc.x2 = 319;
dsp.scinf[0].sc.y2 = 239;
dsp.scinf[0].view.x1 = 0;
dsp.scinf[0].view.y1 = 0;
dsp.scinf[0].view.x2 = 319;
dsp.scinf[0].view.y2 = 239;
dsp.scinf[0].dlgArea.x1 = 2;
dsp.scinf[0].dlgArea.y1 = 14;
dsp.scinf[0].dlgArea.x2 = 319-2;
dsp.scinf[0].dlgArea.y2 = 239-10;
MosInf.scrollPage = 0xFF; /* スクロールなし */
DSP_sysInit( &dsp );
DSP_set_defFnt( FNTYPE_USR1 );
GetFnt12Ptr(0); /* ank font 12 初期設定 */
KBF_sysInit(); /* キーボードシステム初期化 */
KBF_kan_off(); /* かな漢字変換禁止 */
FDL_sysInit(); /* ファイルダイアログ */
sdk_control(0); /* サイドワーク起動禁止 */
/* DLL システム初期化 */
_XLD_init(NULL);
_XLD_setMemFunc( malloc, free );
{
char tmp[256];
int len;
FS_setStartPath( tmp, *argv[0] );
if ( (len = strlen(tmp)) > 0 )
tmp[--len] = '\0';
_XLD_setLinkPath( tmp );
}
_XLD_lockLib( MID_playStatFlag );
/* MIDI BGM システム初期化 */
MID_sysInit();
/* パレット設定 */
DSP_writePage(1);
DSP_setPlt(PltDat);
/* タイトル表示 */
DSP_writePage(1);
DSP_title( _ZNSPLAY_, MAIN_VER, C_HWHITE, C_WHITE, C_MBLACK, C_HBLACK );
/* ファイルダイアログ */
FdlDefColTbl[0] = C_DLGBASE;
Fdl_set_doscall( DOScons_open, DOScons_close, system);
Fdl_set_sidework( SideWorkMenu );
FdlSetWildCardList( ZNS_WILD_ALL );
FdlSetWildCardList( ZNS_WILD_MOV );
/* FdlSetWildCardList( ZNS_WILD_V00 ); */
FdlSetWildCardList( ZNS_WILD_V02 );
return (NORMAL);
}
static void term(void)
{
MID_sysEnd();
FDL_sysEnd();
KBF_sysEnd();
DSP_sysEnd();
if ( SndPtr )
{
SND_end();
free(SndPtr);
SndPtr = NULL;
}
reset24h();
}
static void help(void)
{
static CONST char help_msg[] = "\
usage : znsplay [<option>] [<filename>] \n\
<option> \n\
-wait <n> ... wait time (n:0~99) \n\
-display <n> ... display mode (n:1~4) \n\
-disk ... disk play mode \n\
-memory ... memory play mode \n\
-chkPort <right/left/both> \n\
... pause & stop check port \
";
DSP_writePage(1);
DLG_tmpMsgBox ( DLGPOS_CENTER_OF_SCN, DLGPOS_CENTER_OF_SCN,
DspCtrl.black, C_DLGBASE, COLMIX(C_INFO,C_GRAY),
"“UGOKUZANSU” movie data player %s ver.%s\n\n%s",
_ZNSPLAY_, MAIN_VER, help_msg );
}
static int errFunc( CONST char *s )
{
/* return (-1) 即中断 */
/* return (1) エラーは無視して中断 */
/* return (0) エラーは無視 */
return (0);
}
/*************************************************************************
* オプションパラメータの解析/設定
*************************************************************************/
static int set_option( int argc, char **argv )
{
static int helpVar = 0;
static GOP_DIGIT_T waitPar = { 0, 0, 99 };
static GOP_DIGIT_T displayPar = { 1, 1, 4 };
static int memoryVar = 0;
static int diskVar = 0;
extern int ZnsSwPort;
static GOP_SELECT_OBJ_T ZnsSwPortObj[3] =
{
{1,"left" },
{2,"right"},
{3,"both" },
};
static GOP_SELECT_T ZnsSwPortPar = {3, ZnsSwPortObj};
static GOPKEY_T GetoptKey[] =
{
{ GOP_TYP_FLAG , "?" , GOP_VAR_INT , &helpVar , NULL },
{ GOP_TYP_DIGIT , "wait" , GOP_VAR_INT , &ZnsMove.wait , &waitPar },
{ GOP_TYP_DIGIT , "display" , GOP_VAR_INT , &ZnsMove.expand , &displayPar },
{ GOP_TYP_FLAG , "memory" , GOP_VAR_INT , &memoryVar , NULL },
{ GOP_TYP_FLAG , "disk" , GOP_VAR_INT , &diskVar , NULL },
{ GOP_TYP_SELECT, "chkPort" , GOP_VAR_INT , &ZnsSwPort , &ZnsSwPortPar},
{ -1 , NULL , 0 , NULL , NULL },
};
GOP_T gop = {GOP_MODE_NORMAL,"-/",GetoptKey,errFunc,0,NULL};
if ( argc < 2 )
return (NORMAL);
if ( GOP_decode(&gop,argc-1,&argv[1]) == NORMAL )
{
if ( helpVar )
help();
if ( memoryVar )
ZnsMove.mode = ZNS_MODE_MEMORY;
else if ( diskVar )
ZnsMove.mode = ZNS_MODE_DISK;
{
GOPETC_T *etc = gop.etc;
if ( etc && etc->s[0] )
strcpy( ZnsMove.filename, etc->s );
}
}
GOP_free( &gop );
return (NORMAL);
}
#if 0
static int set_option( int argc, char **argv )
{
int i, mm;
char *s;
int nextopt(void)
{
if ( ++i == argc )
return (-1);
s = argv[i];
if ( *s == '?' || *s == '-' || *s == '/' )
return (1);
return (0);
};
#define CHKNEXT() if((mm=nextopt())<0){goto L_END;}else if(mm>0){goto L_NEXT;}
int help_flag = FALSE;
for ( i = 1; i < argc; ++i )
{
s = argv[i];
L_NEXT:
if ( *s == '?' )
{
help_flag = TRUE;
} else if ( *s == '-' || *s == '/' )
{
++s;
if ( *s == '?' )
{
help_flag = TRUE;
} else if ( strcmpi( s, "wait") == 0 )
{
int wait;
ZnsMove.wait = 0;
CHKNEXT();
wait = atoi(s);
if ( wait >= 0 && wait <= 99 )
ZnsMove.wait = wait;
} else if ( strcmpi( s, "display") == 0 )
{
int expand;
ZnsMove.expand = 1;
CHKNEXT();
expand = atoi(s);
if ( expand >= 1 && expand <= 4 )
ZnsMove.expand = expand;
} else if ( strcmpi( s, "disk") == 0 )
{
ZnsMove.mode = ZNS_MODE_DISK;
} else if ( strcmpi( s, "memory") == 0 )
{
ZnsMove.mode = ZNS_MODE_MEMORY;
}
} else if ( ZnsMove.filename[0] == '\0' )
{
strcpy( ZnsMove.filename, s );
}
}
L_END:
if ( help_flag )
help();
return (NORMAL);
}
#endif
void main(int _argc, char *_argv[])
{
int ret;
int argc;
char **argv;
if ( init(&argc,&argv,_argc,_argv) )
{
ret = 1;
} else
{
if ( argc > 1 && set_option(argc,argv) )
{
ret = 1;
} else
{
zns_main();
ret = 0;
}
term();
}
pcl_exit(0);
exit(ret);
}